package com.ostrich.a2104shopping.ui.home.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @Author : yaotianxue
 * @Time : On 2023/10/7 08:22
 * @Description : ImageBannerAdapter
 */
public class ImageBannerAdapter extends BannerAdapter<String, ImageBannerAdapter.BannerViewHolder> {


    public ImageBannerAdapter(List<String> datas) {
        super(datas);
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        return new BannerViewHolder(imageView);
    }

    @Override
    public void onBindView(BannerViewHolder holder, String data, int position, int size) {
       ImageView imageView = holder.mImageView;


        Glide.with(imageView)
                .load(data)
                .transform(new CenterCrop())
                .into(imageView);

    }

    class BannerViewHolder extends RecyclerView.ViewHolder{
        ImageView mImageView;
        public BannerViewHolder(ImageView imageView) {
            super(imageView);
            mImageView = imageView;
        }
    }

}
